/*
 * @Description: BaseTable上下文
 * @Author: seadon
 * @LastEditors: seadon
 * @Date: 2021-05-18 11:29:55
 * @LastEditTime: 2021-05-18 17:36:42
 */
import { provide, inject, ComputedRef } from 'vue'
import { BasicTableProps, TableActionType } from '../types/table'

const key = Symbol('base-table')

type Instance = TableActionType & {
	getTableProps: ComputedRef<Recordable>
}

type RetInstance = Omit<Instance, 'getTableProps'> & {
	getTableProps: ComputedRef<BasicTableProps>
}

export function createTableContext(instance: Instance) {
	provide(key, instance)
}

export function useTableContext(): RetInstance {
	return inject(key) as RetInstance
}
